import { Service } from "cl-admin";
import BaseService from "@/service/base";
import { last } from "cl-admin/utils";

@Service("OnSale")
class Onsale extends BaseService {
	//接收定金报表
	reportdeposit({ date = [], bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id.join()
		};
		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		};
		return this.$get("/reportdeposit", { params })
	}
	//售中个人报表
	reportPersonal({ date = [], bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id.join()
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		};
		return this.$get('/reportPersonal', { params });
	}
	//售中目标报表
	reportonsale({ date = [], bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id.join()
		};
		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		};
		return this.$get('/reportonsale', { params });
	}
	//售中落地页添加推广部门列表
	getlandlist(params) {
		return this.$get('/set/lists', { params })
	}
	// 删除部门推广
	depDel(params) {
		return this.$post("/set/del", params);
	}
	// 添加部门推广
	setAdd(params) {
		return this.$post("/set/add", params);
	}

	// 编辑部门推广
	setEdit(params) {
		return this.$post("/set/edit", params);
	}

	//售中部门报表
	onsaledepreport({ date = [], dept_ids = [], bra_id = [], ...args }) {
		let params = {
			dept_id: dept_ids.join(),
			bra_id: bra_id.join(),
			...args
		};
		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		};
		// if (dept_ids && dept_ids.length) {
		//     params.dept_id = last(dept_ids);
		// }
		return this.$get("/reportdept", { params });
	}

	//售中门店报表
	onsalestorerep({ date = [], bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id.join()

		};
		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		};
		return this.$get("/reportshop", { params });
	}
	// 城市报表 （售中部门）
	reportcity({ date = [], bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id.join()

		};
		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		};
		return this.$get("/reportcity", { params });
	}

	/**
	 * 部门目标列表
	 */
	page({ size, dept_ids, ...args }) {
		let params = {
			...args,
			pagesize: size,
			dept_id: dept_ids.join()
		};
		// if (dept_ids && dept_ids.length) {
		//     params.dept_id = last(dept_ids);
		// }
		return this.$get("/lists", { params }).then(res => {
			return {
				list: res.data,
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}

	//修改目标
	edittarget(param) {
		return this.$post("/edit", param);
	}

	//删除目标
	deltarget(param) {
		return this.$post("/delete", param);
	}

	//目标日跟踪详情
	daytargetdetail(param) {
		return this.$post("/details", param);
	}

	//售中日跟踪底部报表
	onsaledaytable(param) {
		return this.$post("/detailsReport", param);
	}

	//日跟踪部门明细
	onsaledepdetail(param) {
		return this.$post("/deptdetailed", param);
	}

	//目标组员任务详情
	groupdetail(param) {
		return this.$post("/teamdetails", param);
	}

	//删除组员目标
	teamtargetdel(param) {
		return this.$post("/teamgoalsdelete", param);
	}

	//组员目标修改
	teamtargetedit(param) {
		return this.$post("/teamgoalsedit", param);
	}

	//新增组员目标
	addgrouptarget(param) {
		return this.$post("/teamgoalsadd", param);
	}

	//添加部门月目标
	adddeptarget(param) {
		return this.$post("/add", param);
	}

}
export default Onsale
